<template>
	<div class="container">
		<div class="jx-container">
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          店铺列表
          <div class="add-new">
            <el-button class="jx-btn" type="primary" @click="addRow">新增店铺类型</el-button>
          </div>
        </div>
        <el-table :data="list" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="60" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="shopCatalogName" label="店铺类型" align="center" width="130">
          </el-table-column>
          <el-table-column prop="depositQuota" label="保证金额度" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="franchiseFee" label="加盟费" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="techServiceFee" label="技术服务费" align="center" >
          </el-table-column>
          <el-table-column prop="serviceDiscount" label="服务费扣点" align="center" >
          </el-table-column>
          <el-table-column prop="serviceProviderYearFee" label="服务商年费" align="center">
          </el-table-column>
          <el-table-column label="操作" width="210" align="center">
            <template slot-scope="scope">
              <el-button @click="editRow(scope.row)" type="text" size="small">编辑</el-button>
              <el-button @click="deleteRow(scope.row)" type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div v-if="list.length != 0" class="jx-pagination">
          <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
    <!-- 新增店铺 -->
    <el-dialog  :visible.sync="boo.showDialog" class="jx-dialog" width="65%">
      <div slot="title" class="header-title">
        <span class="title-name">{{currentRow.shopCatalogId ? '编辑店铺' : '新增店铺'}}</span>
      </div>
      <el-form ref="form" :model="currentRow" :rules="rules" label-width="150px" class="jx-form">
        <div class="jx-detail">
          <div class="detail-item">
            <div class="item">
              <el-form-item label="店铺类型：" prop="shopCatalogName">
                <el-input v-model="currentRow.shopCatalogName" placeholder="请输入店铺类型名称"></el-input>
              </el-form-item>
              <el-form-item label="保证金额度：" prop="depositQuota">
                <el-input v-model="currentRow.depositQuota" placeholder="请输入保证金额度"></el-input>
              </el-form-item>
              <el-form-item label="加盟费：" prop="franchiseFee">
                <el-input v-model="currentRow.franchiseFee" placeholder="请输入加盟费"></el-input>
              </el-form-item>
              <el-form-item label="技术服务费：" prop="techServiceFee">
                <el-input v-model="currentRow.techServiceFee" placeholder="请输入技术服务费"></el-input>
              </el-form-item>
              <el-form-item label="服务费扣点：" prop="serviceDiscount">
                <el-input v-model="currentRow.serviceDiscount" placeholder="请输入服务费扣点"></el-input>
                <span>%</span>
              </el-form-item>
              <el-form-item label="服务商年费：" prop="serviceProviderYearFee">
                <el-input v-model="currentRow.serviceProviderYearFee" placeholder="请输入服务商年费"></el-input>
              </el-form-item>
              <el-form-item label="协议：" prop="agreement">
                <vue-editor :content="currentRow.agreement" @getcontent="getcontent"></vue-editor>
              </el-form-item>
            </div>
          </div>
        </div> 
      </el-form>
      <div class="btn-container">
        <el-button class="jx-btn" type="warning" @click="boo.showDialog = false">取消</el-button>
        <el-button class="jx-btn" type="primary" :loading="boo.saveing" @click="submitRow('form')">保存</el-button>
      </div>
    </el-dialog>
	</div>
</template>

<script>
  import VueEditor from '@/components/common/VueEditor'
	export default {
    components: { VueEditor },
		data() {
			return {
        https: {
          list: this.$api.setting.shop,
          type: this.$api.common
        },
        boo: {
          loading: false,
          showDialog: false,
        },
        other: {
          allRow: 1,
          saveing: false,
        },
        list: '',
        currentRow: {},
        params_list: {
          page: 1,
          size: 10,
        },
        rules: {
          depositQuota: [{ required: true, message: '请输入保证金额度', trigger: 'blur' }],
          franchiseFee: [{ required: true, message: '请输入加盟费', trigger: 'blur' }],
          shopCatalogName: [{ required: true, message: '请输入店铺类型名称', trigger: 'blur' }],
          techServiceFee: [{ required: true, message: '请输入技术服务费', trigger: 'blur' }],
          serviceDiscount: [{ required: true, message: '请输入服务费扣点', trigger: 'blur' }],
          serviceProviderYearFee: [{ required: true, message: '请输入服务商年费', trigger: 'blur' }],
          agreement: [{ required: true, message: '请输入协议内容', trigger: 'blur' }],
        },
			}
		},
		mounted(){
      let _self = this
      _self.getList()
    },
		methods: {
      getList(){
        let _self = this
        let params = {
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
          orderBy: '',
        }
        _self.boo.loading = true
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.list = res.retObject.list
            _self.other.allRow = Number(res.retObject.totalRow)
          }else{
            _self.$message.error(res.retMsg)
          }
          _self.boo.loading = false
        }
        _self.$axios.get(_self.https.list.list, params, success) 
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      addRow(){
        let _self = this
        _self.boo.showDialog = true
        _self.currentRow = {}
      },
      viewProtocol(){},
      editRow(item){
        let _self = this
        _self.boo.showDialog = true
        _self.currentRow = JSON.parse(JSON.stringify(item))
      },
      // 删除
      deleteRow(item){
        let _self = this
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.getList()
          }else{
            _self.$message.error(res.retMsg)
          }
        }
        _self.$axios.delete(`${_self.https.list.detail}${item.shopCatalogId}`, {}, success)
      },
      getcontent(val){
        this.currentRow.agreement = val
      },
      submitRow(formName){
        let _self = this
				this.$refs[formName].validate((vaild)=>{
					if(vaild){  
            let params = {
              shopCatalogName: _self.currentRow.shopCatalogName,
              depositQuota: _self.currentRow.depositQuota,
              franchiseFee: _self.currentRow.franchiseFee,
              techServiceFee: _self.currentRow.techServiceFee,
              serviceDiscount: _self.currentRow.serviceDiscount,
              serviceProviderYearFee: _self.currentRow.serviceProviderYearFee,
              agreement: _self.currentRow.agreement,
            }
            _self.boo.saveing = true
            let success = (res)=>{
              res = res.data
              if(res.retCode == 1){
                _self.getList()
              }else{
                _self.$message.error(res.retMsg)
              }
              _self.boo.saveing = false
              _self.boo.showDialog = false
            }
            if(_self.currentRow.shopCatalogId){
              _self.$axios.put(`${_self.https.list.detail}${_self.currentRow.shopCatalogId}`, params, success)
            }else {
              _self.$axios.post(_self.https.list.add, params, success)
            } 
					}else{
						return false
					}
				})
      }
    }
	}

</script>
<style scoped lang="sass">
</style>
